package com.example.demo2022.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo2022.entity.Role;
import com.example.demo2022.mapper.RoleMapper;
import com.example.demo2022.service.IRoleService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/************************************
 * @PACKAGE : com.example.demo2022.service.impl
 * @Author    :  叫我老伯
 * @Date    : 2022/5/31 19:51
 * @Desc    :
 ***********************************/
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {
    @Override
    public List<Role> listRoleByUserId(Long userId) {
        //查询到所有的角色
        List<Role> roleAllList = this.list();
        //查询到当前用户的角色
        Set<Long> userRoleSet =  this.baseMapper.listRoleIdByUserId(userId);
        //遍历设置选中
        for(Role role : roleAllList){
            if (userRoleSet.contains(role.getId())) {
                role.setChecked(true);
            }
        }

        return roleAllList;
    }
}
